<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/commons/taglibs.jsp" %>
 
<script src="${ctx}/includes/jquery.js" type="text/javascript"></script>
<script src="${ctx}/includes/jquery.form.js" type="text/javascript"></script>
<script src="${ctx}/includes/jquery.validate.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="${ctx}/style/form_table.css">
<s:form id="edit_meeting_form" name="edit_meeting_form" method="post" action="meeting/update.do"  enctype="multipart/form-data">
	<s:hidden id="id" name="id" />
	<table class="form-table">
		<tr>
			<th width="150">会议主题：</th>
			<td>
			${zt}
			</td>
		</tr>
		<tr>
			<th width="150">会议日期：</th>
			<td>
			${hyrqString}
			</td>
		</tr>
		<tr>
			<th width="150">会议时间：</th>
			<td>
			${strtime}
			</td>
		</tr>
		<tr>
			<th width="150">会议室：</th>
			<td>
			${dataname}
			</td>
		</tr>
		<tr>
			<th width="150">预定人：</th>
			<td>
			${realname}
			</td>
		</tr>
		<%-- 
		<tr>
			<th width="110">会议内容：</th>
			<td>
			<textarea rows="4" name="bz" style="width:400px;" title="请填写会议内容">${bz}</textarea>
			</td>
		</tr>
		--%>
		<tr>
			<th width="110">会议议题1：</th>
			<td>
			<textarea rows="2" name="yt1" style="width:400px;" title="请填写会议议题" id="yt1">${yt1}</textarea>
			</td>
		</tr>
		<tr>
			<th width="110">会议议题2：</th>
			<td>
			<textarea rows="2" name="yt2" style="width:400px;" title="请填写会议议题" id="yt2">${yt2}</textarea>
			</td>
		</tr>
		<tr>
			<th width="110">会议议题3：</th>
			<td>
			<textarea rows="2" name="yt3" style="width:400px;" title="请填写会议议题" id="yt3">${yt3}</textarea>
			</td>
		</tr>
		<tr>
			<th width="110">会议议题4：</th>
			<td>
			<textarea rows="2" name="yt4" style="width:400px;" title="请填写会议议题" id="yt4">${yt4}</textarea>
			</td>
		</tr>
		<tr>
			<th width="150">参与人员：</th>
			<td>
				<select multiple="multiple" size="4" id="users" title="请选择参与人员" name="attendUsers" style="width: 120px;;border:1px solid #DAE0E5;height:150px;" >
					<c:forEach items="${meetingUsers}" var="item2" varStatus="status2">
						<option value="${item2.userid}" selected>${item2.username}</option>
					</c:forEach>
				</select>
				<span>
				<a class="btn_short" href="javascript:void(0)" title="添加用户" name="btn_addAttendUsers" id="btn_attendUsers"
					onClick="selectUser()">选择</a>
				<a class="btn_short" href="javascript:void(0)" title="删除用户" name="btn_delAttendUsers" id="btn_delAttendUsers" 
					onClick="deleteUser();">删除</a>
				</span>
			</td>
		</tr>
		<tr>
			<th width="150">已上传附件：</th>
			<td id="files">
				<c:if test="${attach != null}">
			  		<c:forEach items="${attach}" var="item" varStatus="status">
						 <a href="${ctx}/filedownload.do?fileAsName=${item.attachid}" target="_blank"> ${item.name} </a>
						  &nbsp;<a href="#" onclick="delAttach('${item.attachid}')">删除</a><br/>
			  		</c:forEach>
			  	</c:if>
			</td>
		</tr>
		<tr>
			<th width="150">附件：</th>
			<td id="files">
			<input name="attachFile" type="file" size="50"/>
			</td>
		</tr>
	</table>
	 <br/>
	<div class="win-btn-panel" align="center">
	   		<input class="btn-short" type="button" onclick="editMeeting()" value="确定" title="确定" >
	</div>
</s:form>
<script type="text/javascript">
function selectUser(){
  parent.$.dialog({
  	id:'xzry', 
  	name:'xzry',
  	title:'选择人员', 
  	content: 'url:${ctx}/pub/userAllSelect.jsp?timestamp='+new Date().getTime(), 
  	max:false,
  	min:false,
  	width:600, 
  	height:450,
  	ok: function(){ 
       	parent.xzry.selectMoreByMeetingUser();
        return true; 
    }, 
    cancelVal: '关闭', 
    cancel: true
  });
}

function deleteUser(){
	var selectObj = document.getElementById("users");
	var selectOptions = selectObj.options;
	if (selectOptions == null || selectOptions.length == 0 || selectOptions.selectedIndex == -1){
		var msg="请先选择要删除的人员！";
		alert(msg);
		return;
	}
	var ilen=selectOptions.length;
	for (var i=ilen-1; i>=0; i--){
		if(selectObj[i].selected)
		    selectObj.remove(i);
	}
}


	$(function(){
			$("#edit_meeting_form").validate({
				errorPlacement: function(error, element){
		            $(element).next('.field_notice').hide();
		            $(element).after(error);
		       },
			   success: function(label){   
			       label.addClass('right').text('OK!');
			   },
			   rules:   
			   {
	            	attendUsers:{required : true},
	            	bz: {required : true}
			   },   
			   message:{
	            	attendUsers:{required : '请选择参与人员'},
	            	bz : {required : '请填写内容'}
			   },
			   submitHandler: function() {
			   		editMeeting();
			   }
			});  
		});
		
function editMeeting(){
	var selectObj = document.getElementById("users");
	var selectOptions = selectObj.options;
	if (selectOptions == null || selectOptions.length == 0){
		alert('请选择人员');
		return;
	}else{
		for (var i=0;i<selectOptions.length;i++){
			selectObj[i].selected = true;
		}
	}
	var v = $("#edit_meeting_form").valid();
	if(v){
		var yt1 = $('#yt1').val();
		var yt2 = $('#yt2').val();
		var yt3 = $('#yt3').val();
		var yt4 = $('#yt4').val();
		if(yt1 == "" && yt2 == "" && yt3 == "" && yt4 == ""){
			alert("至少填写一个议题！");
			return ;
		}
		
		$('#edit_meeting_form').ajaxSubmit(resultHandler);
    	return false;
    }else{
    
    }
}

function delAttach(A){
	if(confirm('您确定要删除附件吗？')){
		jQuery.ajax({
		   	type:'post',	
		   	url:'${ctx}/attach/deleteById.do?attachid='+A+'&timestamp='+new Date().getTime(),
		   	dataType:'xml',
		   	success:resultHandler,
		    error:resultHandler
		});
	}
}

function resultHandler(responseXML){
	var result = responseXML.getElementsByTagName("result")[0].firstChild.nodeValue;
	var message = responseXML.getElementsByTagName("error-message")[0].firstChild.nodeValue;
	var errorType = responseXML.getElementsByTagName("error-type")[0].firstChild.nodeValue;
	if(!eval(result)&&(errorType!=2)){
		alert(message);
	}else{
		var curDate = new Date(); 
		alert(message);
		parent.window.location.href = "${ctx}/meeting_myMeeting.do?timsStamp=" + curDate.getTime();
	}
}

</script>